<?php
	namespace Chiefs\Controller;
	use Think\Controller;
	use Think\Tools;
class IndexController extends Controller{

	//注册用户个人首页展示(展示首页所有信息)
	public function Index(){
		if ($this->checkUser()) {
			$this->display();
		}else{
			$this->redirect(U('/'));
		}
	}
	/**
	 * 用户信息表
	 * 将接收条件
	 * 
	 */
	public function setUsers(){
		if ($this->checkUser()) {
			$num = D('users')->count();
			$Page = new \Think\Page($num,5);
			$config['limit'] = $Page->firstRow.','.$Page->listRows ;
			$All_users = $this->users($config);
			$page = $Page->show();
			$view='';
			foreach ($All_users as $k => $v) {
				$view = $view.'<tr style="'.'border-bottom:1px solid #999;'.'">';
	            $view = $view.'<td>'.$v['uid'].'</td>';
	            $view = $view.'<td><a href="'.U("/Chiefs/Index/index",array('uid'=>$v['uid'])).'">'.$v['username'].'</a></td>';
	            $view = $view.'<td>'.$v['mobile'].'</td>';
	            $view = $view.'<td><a href="'.U("/Chiefs/Index/index",array('uid'=>$v['uid'])).'">'.'管理'.'</a></td></tr>';
			}
			$arr = array(0=>$page,1=>$view);
			$json = json_encode($arr);
				//echo 666;exit();
				echo $json;exit();
		}else{
			$this->redirect(U('/'));
		}
	}
	public function arts(){
		if ($this->checkUser()) {
			$num = D('users')->count();
			$Page = new \Think\Page($num,10);
			$config['limit'] = $Page->firstRow.','.$Page->listRows ;
			$All_users = $this->users($config);
			$page = $Page->show();
			$this->assign('page',$page);
			$this->assign('users',$All_users);
			$this->display();
		}else{
			$this->redirect(U('/'));
		}
	}	
	/**
	 * 用户查询表
	 * 
	 * 
	 * 
	*/
	public function users($config){
			$f = $config['field']?$config['field']:' *';
			$w = $config['where']?$config['where']:' 1';
			$o = $config['order']?$config['order']:' uid';
			$l = $config['limit']?$config['limit']:' 0,-1';
			$M_users = D('users');
		if ($config['limit']) {
			$users = $M_users->field($f)->where($w)->order($o)->limit($l)->select();
		}else{
			$users = $M_users->field($f)->where($w)->order($o)->select();
		}
		if ($users) {
			return $users;
		}else{
			echo '查询失败';exit();
		}
	}
	/**
	 * @author hansir
	 * 添加构造函数
	 */
	private function checkUser(){
		return true;
	}

}